const mongoose = require('mongoose')
const Schema = mongoose.Schema;

const Article = new Schema({
	title: { type: String, required: [true, 'Why no title?'], trim: true, maxlength: 50 },
	body: { type: String,  required: [true, 'Why no body?'], trim: true, maxlength: 10000 },
	user: { type: Schema.ObjectId, ref: 'User' },
	comments: [
		{
			body: { type: String, default: '', maxlength: 1000 },
			user: { type: Schema.ObjectId, ref: 'User' },
			createdAt: { type: Date, default: Date.now }
		}
	],
	createdAt: { type: Date, default: Date.now },
	removed: {type: Boolean, default: false, required: true},
	removedAt: {type: Date},
	lastModifiedAt: {type: Date, default: Date.now, required: true}
})

module.exports = mongoose.model('Articles', Article)